package com.tbit.uqbike.webmanager.controller;

import com.tbit.common.constant.MethodEnum;
import com.tbit.common.constant.ModuleEnum;
import com.tbit.common.enums.OperaPswEnum;
import com.tbit.uqbike.annos.OperateLog;
import com.tbit.uqbike.object.pojo.VipFee;
import com.tbit.uqbike.object.view.JsonResult;
import com.tbit.uqbike.service.business.OperaPswService;
import com.tbit.uqbike.service.business.VipFeeService;
import com.tbit.uqbike.webmanager.util.ServletUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 会员卡计费规则Controller
 *
 * @author jing
 * @date 2021-04-20
 */
@RestController
@RequestMapping("/vipfee")
public class VipFeeController extends BaseController {
    @Autowired
    private VipFeeService vipFeeService;
    @Autowired
    private OperaPswService operaPswService;

    /**
     * 获取会员卡计费规则详细信息
     */
    @GetMapping(value = "/{vipId}")
    public JsonResult getInfo(@PathVariable("vipId") Integer vipId) {
        return JsonResult.ok(vipFeeService.selectVipFeeById(vipId));
    }

    /**
     * 新增会员卡计费规则
     */
    @PostMapping
    @OperateLog(module = ModuleEnum.VIPCARD, methods = MethodEnum.VIPCARD_FEE_EDIT)
    public JsonResult add(@RequestBody VipFee vipFee) {
        /**操作密码校验*/
        operaPswService.checkOperaPsw(BaseController.getLogin(ServletUtils.getRequest()),
                    OperaPswEnum.OPERA_PSW_SYSTEM_CONFIG.getModule(), vipFee.getOperaPsw());

        return JsonResult.toAjax(vipFeeService.insertVipFee(vipFee), getLogin(ServletUtils.getRequest()).context);
    }


    /**
     * 删除会员卡计费规则
     */
    @DeleteMapping("/{vipIds}")
    public JsonResult remove(@PathVariable Integer[] vipIds) {
        return JsonResult.toAjax(vipFeeService.deleteVipFeeByIds(vipIds), getLogin(ServletUtils.getRequest()).context);
    }
}
